package com.hsd.znsh.service;

import com.apicloud.sdk.api.Push;
import com.hsd.znsh.entity.SensorData;
import com.hsd.znsh.repository.SensorDataRepository;
import com.hsd.znsh.utils.DateUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.PageRequest;
import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.AsyncResult;
import org.springframework.stereotype.Service;
import org.springframework.util.concurrent.ListenableFuture;

import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/*
 * @auther: wangjiacai
 *
 * @create: 2018-06-25 15:07:02
 */
@Service
public class PushService {

    @Autowired
    private SensorDataRepository sensorDataRepository;

    private Push push=new Push("A6079186880044","61A5FE78-247C-A607-22E0-60CC73DD3040","https://www.apicloud.com");

    public void pushToUser(String title,String content,String user){
        push(title,content,2,"",user);
    }

    public void pushToUserInfo(String title,String content,String user){
        push(title,content,1,"",user);
    }

    public void pushToUser(String title,String content,List<String> users){
        String user="";
        for(String string:users){
            user+=string+",";
        }
        push(title,content,2,"",user);
    }
    public void pushToUserInfo(String title,String content,List<String> users){
        String user="";
        for(String string:users){
            user+=string+",";
        }
        push(title,content,1,"",user);
    }

    public void pushToGroup(String title,String content,String group){
        push(title,content,2,group,"");
    }

    public void pushToGroupInfo(String title,String content,String group){
        push(title,content,1,group,"");
    }

    public void pushToGroup(String title,String content,List<String> groups){
        String group="";
        for(String string:groups){
            group+=string+",";
        }
        push(title,content,2,group,"");
    }

    public void pushToGroupInfo(String title,String content,List<String> groups){
        String group="";
        for(String string:groups){
            group+=string+",";
        }
        push(title,content,1,group,"");
    }

    public void push(String title,String content,Integer type,String groupNames,String userIds){
        push.pushMessage(title,content,type,0,groupNames,userIds);
    }



}

